/*     */ package com.zimbra.qa.unittest;
/*     */ 
/*     */ import com.zimbra.client.ZFilterAction;
/*     */ import com.zimbra.client.ZFilterAction.ZTagAction;
/*     */ import com.zimbra.client.ZFilterCondition;
/*     */ import com.zimbra.client.ZFilterCondition.HeaderOp;
/*     */ import com.zimbra.client.ZFilterCondition.ZHeaderCondition;
/*     */ import com.zimbra.client.ZFilterRule;
/*     */ import com.zimbra.client.ZFilterRules;
/*     */ import com.zimbra.client.ZMailbox;
/*     */ import com.zimbra.client.ZMessage;
/*     */ import com.zimbra.client.ZTag;
/*     */ import com.zimbra.client.ZTag.Color;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ import junit.framework.TestCase;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestTagFilterRules
/*     */   extends TestCase
/*     */ {
/*     */   private static final String USER_NAME = "user1";
/*     */   private static final String NAME_PREFIX = "TestTagFilterRules";
/*     */   private static final String TAG_NAME = "TestTagFilterRules";
/*     */   private static final String TAG2_NAME = "TestTagFilterRules2";
/*     */   private static final String NEW_TAG_NAME = "TestTagFilterRules new";
/*     */   private ZMailbox mMbox;
/*     */   private ZTag mTag;
/*     */   private ZTag mTag2;
/*     */   private ZFilterRules mOriginalRules;
/*     */   
/*     */   public void setUp()
/*     */     throws Exception
/*     */   {
/*  51 */     cleanUp();
/*     */     
/*  53 */     this.mMbox = TestUtil.getZMailbox("user1");
/*  54 */     this.mTag = this.mMbox.createTag("TestTagFilterRules", ZTag.Color.purple);
/*  55 */     this.mTag2 = this.mMbox.createTag("TestTagFilterRules2", ZTag.Color.green);
/*  56 */     this.mOriginalRules = this.mMbox.getIncomingFilterRules();
/*  57 */     this.mMbox.saveIncomingFilterRules(getRules());
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public void testRenameTag()
/*     */     throws Exception
/*     */   {
/*  66 */     String sender = TestUtil.getAddress("user1");
/*  67 */     String recipient = TestUtil.getAddress("user1");
/*  68 */     String subject = "TestTagFilterRules testRenameTag 1";
/*  69 */     TestUtil.addMessageLmtp(subject, recipient, sender);
/*     */     
/*     */ 
/*  72 */     ZMessage msg = TestUtil.getMessage(this.mMbox, "tag:TestTagFilterRules");
/*  73 */     TestUtil.verifyTag(this.mMbox, msg, "TestTagFilterRules");
/*     */     
/*     */ 
/*  76 */     this.mMbox.renameTag(this.mTag.getId(), "TestTagFilterRules new");
/*     */     
/*     */ 
/*  79 */     ZFilterAction.ZTagAction action = (ZFilterAction.ZTagAction)((ZFilterRule)this.mMbox.getIncomingFilterRules(true).getRules().get(0)).getActions().get(0);
/*  80 */     assertEquals("Tag name didn't change", "TestTagFilterRules new", action.getTagName());
/*     */     
/*     */ 
/*  83 */     subject = "TestTagFilterRules testRenameTag 2";
/*  84 */     TestUtil.addMessageLmtp(subject, recipient, sender);
/*     */     
/*     */ 
/*  87 */     List<ZMessage> messages = TestUtil.search(this.mMbox, "tag:\"TestTagFilterRules new\"");
/*  88 */     assertEquals("Incorrect number of tagged messages", 2, messages.size());
/*  89 */     for (ZMessage msg2 : messages) {
/*  90 */       TestUtil.verifyTag(this.mMbox, msg2, "TestTagFilterRules new");
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public void testDeleteTag()
/*     */     throws Exception
/*     */   {
/*  99 */     ZMailbox mbox = TestUtil.getZMailbox("user1");
/* 100 */     mbox.deleteTag(this.mTag.getId());
/*     */     
/*     */ 
/*     */ 
/* 104 */     String subject = "TestTagFilterRules testDeleteTag";
/* 105 */     TestUtil.addMessageLmtp(subject, "user1", "user1");
/* 106 */     ZMessage msg = TestUtil.getMessage(mbox, "in:inbox subject:\"" + subject + "\"");
/* 107 */     assertEquals(this.mTag2.getId(), msg.getTagIds());
/*     */     
/*     */ 
/* 110 */     ZFilterRule rule1 = TestUtil.getFilterRule(mbox, "TestTagFilterRules");
/* 111 */     assertFalse(rule1.isActive());
/* 112 */     ZFilterRule rule2 = TestUtil.getFilterRule(mbox, "TestTagFilterRules2");
/* 113 */     assertTrue(rule2.isActive());
/*     */   }
/*     */   
/*     */   public void tearDown() throws Exception
/*     */   {
/* 118 */     this.mMbox.saveIncomingFilterRules(this.mOriginalRules);
/* 119 */     cleanUp();
/*     */   }
/*     */   
/*     */   public void cleanUp() throws Exception
/*     */   {
/* 124 */     TestUtil.deleteTestData("user1", "TestTagFilterRules");
/*     */   }
/*     */   
/*     */   private ZFilterRules getRules() throws Exception
/*     */   {
/* 129 */     List<ZFilterRule> rules = new ArrayList();
/*     */     
/*     */ 
/* 132 */     List<ZFilterCondition> conditions = new ArrayList();
/* 133 */     List<ZFilterAction> actions = new ArrayList();
/* 134 */     conditions.add(new ZFilterCondition.ZHeaderCondition("subject", ZFilterCondition.HeaderOp.CONTAINS, "TestTagFilterRules"));
/* 135 */     actions.add(new ZFilterAction.ZTagAction("TestTagFilterRules"));
/* 136 */     rules.add(new ZFilterRule("TestTagFilterRules", true, false, conditions, actions));
/*     */     
/*     */ 
/* 139 */     conditions = new ArrayList();
/* 140 */     actions = new ArrayList();
/* 141 */     conditions.add(new ZFilterCondition.ZHeaderCondition("subject", ZFilterCondition.HeaderOp.CONTAINS, "TestTagFilterRules"));
/* 142 */     actions.add(new ZFilterAction.ZTagAction("TestTagFilterRules2"));
/* 143 */     rules.add(new ZFilterRule("TestTagFilterRules2", true, false, conditions, actions));
/*     */     
/* 145 */     return new ZFilterRules(rules);
/*     */   }
/*     */   
/*     */   public static void main(String[] args) throws Exception
/*     */   {
/* 150 */     TestUtil.cliSetup();
/* 151 */     TestUtil.runTest(TestTagFilterRules.class);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/TestTagFilterRules.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */